
import java.util.ArrayList;
import java.util.Collections;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Afshin
 */
public class Global {

    public static ArrayList<Agent> agents;
    public static int TIME_STEP = 2; // seconds
    public static double WALKING_SPEED = 3 * TIME_STEP; // meters per second
    private static int DEATH_TIME = 120; // seconds
    public static int TURNS_UNTIL_DEATH = DEATH_TIME / TIME_STEP;
    public static boolean killInProgress = false;

    public static int makeGuess(int agentid) {
        // Revisa a tus muertos
        Agent a = Global.agents.get(agentid);
        ArrayList<String> deadfriendlikes = new ArrayList<String>();
        for (int i = 0; i < a.friends.size(); i++) {
            int index = a.friends.get(i);
            if (!Global.agents.get(index).isLiving) {
                for (int j = 0; j < Global.agents.get(index).likes.size(); j++) {
                    String like = Global.agents.get(index).likes.get(j);
                    if (!deadfriendlikes.contains(like)) {
                        deadfriendlikes.add(like);
                    }
                }
            }
        }
        Collections.sort(deadfriendlikes);
        for (int i = 0; i < a.myEvents.size(); i++) {
            if (!a.myEvents.get(i).type.equals("Guess")) {
                int vict = a.myEvents.get(i).getVictimid();
                for (int j = 0; j < Global.agents.get(vict).likes.size(); j++) {
                    String like = Global.agents.get(vict).likes.get(j);
                    if (!deadfriendlikes.contains(like)) {
                        deadfriendlikes.add(like);
                    }
                }
            }
        }
        Collections.sort(deadfriendlikes);
        int poskil = -1;
        ArrayList<Integer> hits = new ArrayList<Integer>();
        for (int i = 0; i < a.friends.size(); i++) {
            int hit = 0;
            for (int j = 0; j < Global.agents.get(i).getDislikes().size(); j++) {
                String dis = Global.agents.get(i).getDislikes().get(j);
                if (deadfriendlikes.contains(dis)) {
                    hit++;
                }
            }
            hits.add(hit);
        }
        int index = 0;
        int temp = 0;
        for (int i = 0; i < hits.size(); i++) {
            if (hits.get(i) > temp) {
                temp = hits.get(i);
                index = i;
            }
        }
        if (hits.get(index) > ((Global.agents.get(a.friends.get(index)).dislikes.size()) / 2)) {
            return a.friends.get(index);
        } else {
            return -1;
        }
    }
    
        public static void wait(int n) {
        long t0, t1;
        t0 = System.currentTimeMillis();
        do {
        t1 = System.currentTimeMillis();
        } while (t1 - t0 < n);
    }
        
         public static int getKiller(ArrayList<Agent> Agents) {
        int index = 0;
        for (int i = 0; i <Agents.size(); i++) {
            if (Agents.get(i).isKiller) {
                index = i;
            }
        }
        return index;
    }
}
